<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport"
    content="width=device-width,initial-scale=1.0,maixmum-scale=1.0,minimum-scale=1.0,user-scalable=no">
  <meta name="referrer" content="no-referrer">
  <script src="<%= BASE_URL %>config.js"></script>
  <title></title>
</head>

<body>

</body>

</html>
<script type="text/javascript" src="./static/map/d3.v3.min.js"></script>
<script type="text/javascript" src="./static/js/jquery-3.7.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<!-- 颗粒 -->
<script src="./static/js/Particleground.js" type="text/javascript"></script>
<script>
// 百度翻译API相关信息
const apiUrl = 'https://api.fanyi.baidu.com/api/trans/vip/translate';
const appId = '20181224000251834';
const appKey = '你的App Key';
const secretKey = 'NtNxxfGXdnfm9UHCknKw';

// 待翻译的文本
const textToTranslate = '你好，城市!';

// 生成随机数
const salt = Math.floor(Math.random() * 100000);

// 计算签名
const sign = appId + textToTranslate + salt + secretKey;
const signMd5 = CryptoJS.MD5(sign).toString(); 


// 构建请求参数
const params = {
  q: textToTranslate,
  from: 'zh',  // 源语言，英语
  to: 'en',    // 目标语言，中文
  appid: appId,
  salt: salt,
  sign: signMd5
};

// 构建请求URL
const url = `${apiUrl}?q=${params.q}&from=${params.from}&to=${params.to}&appid=${params.appid}&salt=${params.salt}&sign=${params.sign}`;

// 发送请求并获取翻译结果
fetch(url)
  .then(response => response.json())
  .then(result => {
    // 解析翻译结果
    const translatedText = result.trans_result[0].dst;
    
    // 打印翻译结果
    console.log(`原文: ${textToTranslate}`);
    console.log(`译文: ${translatedText}`);
  })
  .catch(error => {
    console.error('翻译请求失败:', error);
  });


</script>